<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div class="div-class div-class2"></div>

  <script>
    const elem = document.querySelector('div')

    // 获取
    const className = elem.className // div-class div-class2
    console.log(className)

    // 修改
    elem.className = 'div-class div-class2 div-class3'
  </script>
</body>

</html>